<?php defined("MAIN_DIR") or die("No direct access");

$query = "select `B`.`bank_id`,`B`.`link`,`B`.`name`,SUM(`V`.`mark`) as `rating`
	from `bank` as `B`,`vote` as `V`
	where `B`.`bank_id` = `V`.`bank_id` and `B`.`city_id` = '$_SESSION[city]'
	group by `bank_id`
	order by `rating` desc, `name` limit 8";
$rating_column = $db->getTable($query);

?><div id="reiting_heading"><a href="<?php echo "/$c_name";?>/banks/rating">Рейтинг банков</a></div><?php
if ($rating_column) {

	?><div id="reiting_banks">
		<table width="100%" border="0" cellpadding="0" cellspacing="0"><?php
			$i = 0;
			foreach ($rating_column as $bank_row) {
				$i++;
				?><tr>
					<td width="12%" class="reiting_number reiting_bank"><?php echo $i; ?></td>
					<td width="88%" class="reiting_bank">
						<a href="<?php echo "/$c_name";?>/banks/<?php echo $bank_row['link'].".html"; ?>"><?php echo $bank_row['name']; ?></a>
					</td>
				</tr><?php
			}
		?></table>
	</div><?php
}
?><div id="reiting_gol">
	<a href="<?php echo "/$c_name";?>/mentions/voting/">Проголосовать<br />за банк!</a>
</div>